home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / PowerD / Dmod / dmod_P96 / examples / OpenScreen.d < prev    next >
Encoding:
Text File  |  2002-10-28  |  4.6 KB  |  164 lines

  1. /***********************************************************************
  2. * This is an example that shows how to open a p96 Screen and a Window 
  3. * to get input events and how to paint on that screen.
  4. * Program terminates when space bar or any mouse button is pressed!
  5. *
  6. * alex (Sun Dec 29 01:42:59 1996)
  7. *
  8. * converted by Martin <MarK> Kuchinka, 14.8.2002
  9. ***********************************************************************/
  10.  
  11. MODULE    'libraries/picasso96',
  12.             'picasso96'
  13.  
  14. MODULE    'intuition/intuition',
  15.             'utility/tagitem',
  16.             'graphics/modeid'
  17.  
  18. DEF    P96Base
  19.  
  20. DEF    WindowTags=[
  21.     WA_Width,        200,
  22.     WA_Height,       300,
  23.     WA_MinWidth,     100,
  24.     WA_MinHeight,    100,
  25.     WA_MaxWidth,     -1,
  26.     WA_MaxHeight,    -1,
  27.     WA_SimpleRefresh,TRUE,
  28.     WA_RMBTrap,      TRUE,
  29.     WA_Activate,     TRUE,
  30.     WA_CloseGadget,  TRUE,
  31.     WA_DepthGadget,  TRUE,
  32.     WA_DragBar,      TRUE,
  33.     WA_SizeGadget,   TRUE,
  34.     WA_SizeBBottom,  TRUE,
  35.     WA_GimmeZeroZero,TRUE,
  36.     WA_ScreenTitle,  'Picasso96 API Test',
  37.     WA_IDCMP,        IDCMP_RAWKEY|IDCMP_CLOSEWINDOW,
  38.     TAG_END]:TagItem
  39.  
  40. PROC main()
  41.     IF P96Base:=OpenLibrary(P96NAME,2)
  42.         DEF    rda
  43.         DEF    sc:PTR TO Screen
  44.         DEFL    Width=640,Height=480,Depth=8,DisplayID
  45.         DEF    array=[0,0,0]
  46.  
  47.         IF rda:=ReadArgs('Width=W/N,Height=H/N,Depth=D/N', array, NIL)
  48.             IF array[0] THEN Width :=Long(array[0])
  49.             IF array[1] THEN Height:=Long(array[1])
  50.             IF array[2] THEN Depth :=Long(array[2])
  51.             FreeArgs(rda)
  52.         ENDIF
  53.  
  54.         IF (DisplayID:=p96BestModeIDTags(
  55.                 P96BIDTAG_NominalWidth, Width,
  56.                 P96BIDTAG_NominalHeight,Height,
  57.                 P96BIDTAG_Depth,        Depth,
  58.                 P96MA_FormatsAllowed,   RGBFF_CLUT|RGBFF_R5G6B5|RGBFF_R8G8B8|RGBFF_A8R8G8B8,
  59.                 TAG_DONE))=INVALID_ID
  60.             DisplayID:=p96RequestModeIDTags(
  61.                 P96MA_MinWidth,       Width,
  62.                 P96MA_MinHeight,      Height,
  63.                 P96MA_MinDepth,       Depth,
  64.                 P96MA_WindowTitle,   'RequestModeID Test',
  65.                 P96MA_FormatsAllowed, RGBFF_CLUT|RGBFF_R5G6B5|RGBFF_R8G8B8|RGBFF_A8R8G8B8,
  66.                 TAG_DONE)
  67.         ENDIF
  68.  
  69.         IF sc:=p96OpenScreenTags(
  70.                 P96SA_Width,     Width,
  71.                 P96SA_Height,    Height,
  72.                 P96SA_Depth,     Depth,
  73.                 P96SA_Pens,      [-1]:W,
  74.                 P96SA_Title,     'Picasso96 API Test',
  75.                 P96SA_DisplayID, DisplayID,
  76.                 TAG_DONE)
  77.  
  78.             DEF    wdf:PTR TO Window, wdp:PTR TO Window
  79.             DEF    Dimensions[4]:W
  80.  
  81.             Dimensions[0] := 0
  82.             Dimensions[1] := sc.BarHeight+1
  83.             Dimensions[2] := sc.Width
  84.             Dimensions[3] := sc.Height-sc.BarHeight-1
  85.  
  86.             wdp := OpenWindowTags(NIL,
  87.                 WA_CustomScreen,sc,
  88.                 WA_Title,       'WritePixel',
  89.                 WA_Left,        (sc.Width/2-200)/2 + sc.Width/2,
  90.                 WA_Top,         (sc.Height-sc.BarHeight-300)/2,
  91.                 WA_Zoom,        Dimensions,
  92.                 TAG_MORE, WindowTags)
  93.  
  94.             wdf := OpenWindowTags(NIL,
  95.                 WA_CustomScreen,sc,
  96.                 WA_Title,       'FillRect',
  97.                 WA_Left,        (sc.Width/2-200)/2,
  98.                 WA_Top,         (sc.Height-sc.BarHeight-300)/2,
  99.                 WA_Zoom,        Dimensions,
  100.                 TAG_MORE,       WindowTags)
  101.  
  102.             IF wdf && wdp
  103.                 DEF    rpf=wdf.RPort:PTR TO RastPort
  104.                 DEF    rpp=wdp.RPort:PTR TO RastPort
  105.                 DEF    terminate=FALSE:BOOL
  106.                 DEFUL    signals=(1<<wdf.UserPort.SigBit)|(1<<wdp.UserPort.SigBit)
  107.                 DEFUL    format=p96GetBitMapAttr(sc.RastPort.BitMap, P96BMA_RGBFORMAT)
  108.  
  109.                 Rnd((wdf+wdp)&$8000.0000)    // just to get a negative number
  110.  
  111.                 REPEAT
  112.                     DEFW x1, y1, x2, y2, x3, y3
  113.  
  114.                     x1 := Rnd(wdf.Width)
  115.                     y1 := Rnd(wdf.Height)
  116.                     x2 := Rnd(wdf.Width)
  117.                     y2 := Rnd(wdf.Height)
  118.                     x3 := Rnd(wdp.Width)
  119.                     y3 := Rnd(wdp.Height)
  120.  
  121.                     IF format=RGBFB_CLUT
  122.                         SetAPen(rpf, Rnd(256))
  123.                         RectFill(rpf, Min(x1,x2), Min(y1,y2), Max(x1,x2), Max(y1,y2))
  124.  
  125.                         SetAPen(rpp,Rnd(256))
  126.                         WritePixel(rpp, x3, y3)
  127.                     ELSE
  128.                         p96RectFill(rpf, Min(x1,x2), Min(y1,y2), Max(x1,x2), Max(y1,y2),
  129.                                         ((Rnd(256))<<16)|((Rnd(256))<<8)|(Rnd(256)))
  130.                         p96WritePixel(rpp, x3, y3,
  131.                                         ((Rnd(256))<<16)|((Rnd(256))<<8)|(Rnd(256)))
  132.                     ENDIF
  133.                     IF SetSignal(0, signals) & signals
  134.                         DEF    imsg:PTR TO IntuiMessage
  135.  
  136.                         WHILE imsg:=GetMsg(wdf.UserPort)
  137.                         ELSEWHILE imsg:=GetMsg(wdp.UserPort)
  138.                         ALWAYS
  139.                             IF imsg.Class=IDCMP_CLOSEWINDOW||
  140.                                 (imsg.Class=IDCMP_RAWKEY&&(imsg.Code=$40||imsg.Code=$45))
  141.                                 // Close window, press SPACE bar or ESCAPE key to end program
  142.                                 terminate:=TRUE
  143.                             ENDIF
  144.                             ReplyMsg(imsg)
  145.                         ENDWHILE
  146.                     ENDIF
  147.                 UNTIL terminate
  148.  
  149.                 Forbid()
  150.                 DEF    msg
  151.                 WHILE msg:=GetMsg(wdf.UserPort) DO ReplyMsg(msg)
  152.                 WHILE msg:=GetMsg(wdp.UserPort) DO ReplyMsg(msg)
  153.                 Permit()
  154.             ELSE PrintF('Can''t open window!\n')
  155.  
  156.             IF wdf THEN CloseWindow(wdf)
  157.             IF wdp THEN CloseWindow(wdp)
  158.  
  159.             p96CloseScreen(sc)
  160.         ELSE PrintF('Can''t open screen: \dx\dx\d \h\n',Width,Height,Depth,DisplayID)
  161.         CloseLibrary(P96Base)
  162.     ELSE PrintF('Can''t open picasso96api.library v2+\n')
  163. ENDPROC
  164.